public class Text2 {
    public static void main(String[] args) {
        StringBuffer stringBuffer = new StringBuffer();
        StringBuilder stringBuilder = new StringBuilder();


        long startTime = System.nanoTime();
        for (int i = 0; i < 10000; i++) {
            stringBuffer.append("Hello, World!");
        }
        long endTime = System.nanoTime();
        long stringBufferTimeNanos = endTime - startTime;

        startTime = System.nanoTime();
        for (int i = 0; i < 10000; i++) {
            stringBuilder.append("Hello, World!");
        }
        endTime = System.nanoTime();
        long stringBuilderTimeNanos = endTime - startTime;


        System.out.println("StringBuffer 执行时间: " + stringBufferTimeNanos + " 纳秒");
        System.out.println("StringBuilder 执行时间: " + stringBuilderTimeNanos + " 纳秒");
    }
}